{include file="public/head" /}
  
  <body>
    <div class="x-body">
        <form class="layui-form"  method="post" action="{:url('admin/admin/adminAdd')}">
            <div class="layui-form-item">
                <label for="username" class="layui-form-label">
                    <span class="x-red">*</span>管理员账号
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="username" name="name" required="" lay-verify="required"
                    autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>将会成为您唯一的登入名
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span class="x-red">*</span>管理员类型</label>
                <div class="layui-input-block">
                    <input type="radio" lay-skin="primary" value="1" title="服务商" lay-filter="fws" name="usertype">
                    <input type="radio" lay-skin="primary" value="2" title="物业" lay-filter="wy" name="usertype">
                    <input type="radio" lay-skin="primary" value="3" title="小区" lay-filter="xq" name="usertype">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="username" class="layui-form-label">
                    <span class="x-red">*</span>所属部门:
                </label>
                <div class="layui-input-inline">
                    <select name="department" lay-filter="department" id="department">
                        <option value="">所属部门</option>
                        {if isset($department)}
                        {foreach $department as $add}
                          <option value="{$add}" >{$add}</option>
                        {/foreach}
                        {/if}
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span class="x-red">*</span>角色类型</label>
                <div class="layui-input-block">
                    {foreach $group as $rol}
                        <input type="radio" name="group" lay-skin="primary" title="{$rol.title}" checked="" value="{$rol.id}">
                    {/foreach}
                </div>
            </div>
            <div class="layui-form-item">
                <label for="L_password" class="layui-form-label">
                    <span class="x-red">*</span>密码
                </label>
                <div class="layui-input-inline">
                    <input type="password" id="L_password" name="password" required="" lay-verify="password"
                    autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    6到16个字符
                </div>
            </div>
            <div class="layui-form-item">
                <label for="L_repass" class="layui-form-label">
                    <span class="x-red">*</span>确认密码
                </label>
                <div class="layui-input-inline">
                    <input type="password" id="L_repass" name="repass" required="" lay-verify="repass"
                    autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="L_repass" class="layui-form-label">
                </label>
                <button  class="layui-btn" lay-filter="add" lay-submit="">
                    添加成员
                </button>
            </div>
        </form>
    </div>
    <script>
        layui.use(['form','layer'], function(){
            $ = layui.jquery;
          var form = layui.form
          ,layer = layui.layer;
        
          //自定义验证规则
          form.verify({
            nikename: function(value){
              if(value.length < 6){
                return '昵称至少得6个字符啊';
              }
            }
            ,password: [/(.+){6,12}$/, '密码必须6到12位']
            ,repass: function(value){
                if($('#L_password').val()!=$('#L_repass').val()){
                    return '两次密码不一致';
                }
            }
          }); 
        });
        
        //二级联动
    </script>
    <script>
        layui.use(['form'], function() {
            var form = layui.form
            form.on('radio(fws)', function(f){
                var url = "{:url('admin/Admin/fetchdata')}"
                $.post(url, {usertype: f.value, type: 1}, function(result) {
                    if(result.code==0){
                        var data=result.data;
                        $('#department').html("")
                        var option = "<option value=''>选择所属部门</option>"
                        $('#department').append(option)
                        for (var i = 0; i < data.length; i++) {
                            option = "<option value='" + data[i] + "'>" + data[i] + "</option>"
                            $('#department').append(option)
                        }
                        form.render('select')
                    }else{
                        layer.msg(result.msg, {icon: 2, time: 2000});
                    }

                },'json')
            })
            form.on('radio(wy)', function(f){
                var url = "{:url('admin/Admin/fetchdata')}"
                $.post(url, {usertype: f.value, type: 1}, function(result) {
                    if(result.code==0){
                        var data=result.data;
                        $('#department').html("")
                        var option = "<option value=''>选择所属部门</option>"
                        $('#department').append(option)
                        for (var i = 0; i < data.length; i++) {
                            option = "<option value='" + data[i] + "'>" + data[i] + "</option>"
                            $('#department').append(option)
                        }
                        form.render('select')
                    }else{
                        layer.msg(result.msg, {icon: 2, time: 2000});
                    }

                },"json")
            })
            form.on('radio(xq)', function(f){
                var url = "{:url('admin/Admin/fetchdata')}"
                $.post(url, {usertype: f.value, type: 1}, function(data) {
                    if(result.code==0){
                        var data=result.data;
                        $('#department').html("")
                        var option = "<option value=''>选择所属部门</option>"
                        $('#department').append(option)
                        for (var i = 0; i < data.length; i++) {
                            option = "<option value='" + data[i] + "'>" + data[i] + "</option>"
                            $('#department').append(option)
                        }
                        form.render('select')
                    }else{
                        layer.msg(result.msg, {icon: 2, time: 2000});
                    }
                },"json")
            })
        })
    </script>
    <script>var _hmt = _hmt || []; (function() {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
      })();</script>
  </body>

</html>